<?php
/**
 * Msg is an instance of CActiveRecord (sytem.db.ar). 
 *
 * CActiveRecord is the base class for classes representing relational data. 
 *
 * Eduow :  International system for education (http://www.eduow.com)
 * Copyright 2010, Nikolay Stoitsev
 *
 * Licensed under GNU General Public License version 2
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright 2010
 * @link          http://eduow.com Eduow Project
 * @package       eduow
 * @subpackage    application.models
 * @inheritance   class Msg >> CActiveRecord >> CModel >> CComponent
 * @implements    ArrayAccess, Traversable, IteratorAggregate
 * @since         Eduow v 0.0.4
 * @license       http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License version 2
 */


class Msg extends CActiveRecord
{

	public $name;

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'messages';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('name, msg, subject', 'required'),
			array('to', 'length', 'max'=>80),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		return array(
			'sender'=>array(self::BELONGS_TO, 'User', 'from'),
            		'recever'=>array(self::BELONGS_TO, 'User', 'to'),
		);
	}

	/**
	 * Declares customized attribute labels.
	 * If not declared here, an attribute would have a label that is
	 * the same as its name with the first letter in upper case.
	 */
	public function attributeLabels()
	{
		return array(
	         	'from'=>Yii::t('yii','From'),
             		'name'=>Yii::t('yii','To'),
             		'msg'=>Yii::t('yii','Message'),
            		'subject'=>Yii::t('yii','Subject'),
		);
	}
}
